Repository navigation
Conversation
A class's resolved annotations are a fact about the class. Every validated dataclass instance asks for them (AnnotatedDataclassValidationMixin), and resolving them again for each instance (get_type_hints, compiling each forward reference) was most of building a nested settings object: in Toad's Qt client at a phone's speed, 0.54 s of a sidebar drag's 0.70 s of settings writes, and about half of opening a view's configuration. resolved_class_annotations keeps the answer per class (a WeakKeyDictionary, read-only), and jsonable's own per-class copy of it goes. A class whose annotations do not resolve yet raises and keeps nothing, so a later call resolves it then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolved_class_annotationsnow resolves once per class and keeps the result.A class's resolved annotations are a fact about the class. Before, every validated dataclass instance (
AnnotatedDataclassValidationMixin.__post_init__→validate_annotated_dataclass) resolved them again:get_type_hintsplus compiling each forward reference. In Toad's Qt client that was most of building a nested settings object.WeakKeyDictionarymaps each class to a read-onlyMappingProxyTypeof its annotations.NameErrorand nothing is kept, so a later call resolves it.jsonable. Its own per-class copy of this cache (_FIELD_TYPES_BY_DATACLASS) is removed; it reads the owner's.Measured in Toad's Qt client
qt_drive drag_speed, at phone speed (45% of one core), 3 runs per tree, median. #2107 attributed 0.54 s of its drag's 0.70 s of settings writes to this validation.ObjectConfigurationbuilds it (unthrottled, median of 5):Tests
tests/test_class_annotation_cache.py:🤖 Generated with Claude Code
https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3